//
//  JddPickNumBasketBallTableView.m
//  PlayBall
//
//  Created by Jdd‘s macbook on 13-12-16.
//
//

#import "JddPickNumBasketBallTableView.h"

@implementation JddPickNumBasketBallTableView

- (void)viewDidLoad {
	[super viewDidLoad];
	self.sportlotterylist = [[JddSportNumberList alloc] init];
    
}

- (void)refreshTableView {
	NSArray *tableData = [self.sResult objectFromJSONString];
	CGRect frame = SPORT_CHILD_VIEW_FRAME;
    //让分，胜负，大小分
	if (self.lottId == LOTTERY_PLAY_METHOD_BASKETBALL_RFSF
	    || self.lottId == LOTTERY_PLAY_METHOD_BASKETBALL_SF
        || self.lottId == LOTTERY_PLAY_METHOD_BASKETBALL_DXF) {
        
		[tableViewRFSF removeFromParentViewController];
		[tableViewRFSF.view removeFromSuperview];
		tableViewRFSF = [[Jdd_RFSF_TableView alloc] init];
		tableViewRFSF.tableData = tableData;
		tableViewRFSF.delegate = self;
		tableViewRFSF.lottId = self.lottId;
		tableViewRFSF.sportlotterylist = self.sportlotterylist;
        
		[self addChildViewController:tableViewRFSF];
		tableViewRFSF.view.frame = frame;
		[self.view addSubview:tableViewRFSF.view];
	}
    //胜分差
    else if (self.lottId == LOTTERY_PLAY_METHOD_BASKETBALL_SFC){
        [tableViewSFC removeFromParentViewController];
		[tableViewSFC.view removeFromSuperview];
		tableViewSFC = [[JddBasketBall_SFC_TableView alloc] init];
		tableViewSFC.tableData = tableData;
		tableViewSFC.delegate = self;
		tableViewSFC.lottId = self.lottId;
		tableViewSFC.sportlotterylist = self.sportlotterylist;
        
		[self addChildViewController:tableViewSFC];
		tableViewSFC.view.frame = frame;
		[self.view addSubview:tableViewSFC.view];
    }
    //混合
	else if (self.lottId == LOTTERY_PLAY_METHOD_BASKETBALL_HH) {
		[tableViewHH removeFromParentViewController];
		[tableViewHH.view removeFromSuperview];
		tableViewHH = [[JddBasketBall_HH_TableView alloc] init];
		tableViewHH.tableData = tableData;
		tableViewHH.delegate = self;
		tableViewHH.sportlotterylist = self.sportlotterylist;
		[self addChildViewController:tableViewHH];
		tableViewHH.view.frame = frame;
		[self.view addSubview:tableViewHH.view];
	}
}

- (void)selectMatch {
	NSString *label3Text = @"----";
	if ([self.sportlotterylist.sportList count] > 0) {
		JddSportNumber *sportnum1 = [self.sportlotterylist.sportList objectAtIndex:0];
		NSDate *date1 = [JddCommonFunction dateFromString:sportnum1.endTime];
		for (JddSportNumber *sportnum in self.sportlotterylist.sportList) {
			NSDate *date2 = [JddCommonFunction dateFromString:sportnum.endTime];
			date1 = [date2 earlierDate:date1];
		}
		NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
		[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
		label3Text = [dateFormatter stringFromDate:date1];
	}
	NSString *label2Text = [NSString stringWithFormat:@"共选择%d场比赛,截止时间：", [self.sportlotterylist.sportList count]];
    
	[self.delegate performSelector:@selector(selectMatch::) withObject:label2Text withObject:label3Text];
}

@end
